package ext.generic.wfaugment;

import wt.inf.container.WTContainer;

import wt.org.WTGroup;
import wt.org.WTPrincipal;
import wt.org.WTUser;

import wt.util.WTException;

import com.ptc.core.components.descriptor.DataUtilityHelper;
import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.AbstractDataUtility;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.TextDisplayComponent;
/**
 *流程参与者表格定制显示信息的DataUtility
 * @author Harry Cao
 */
public class ParticipantsDataUtility extends AbstractDataUtility
{

    public ParticipantsDataUtility()
    {
    }

    public Object getDataValue(String s, Object obj, ModelContext modelcontext) throws WTException
    {
        GUIComponentArray guiComponentArray = new GUIComponentArray();

        if (obj instanceof WTPrincipal)
        {
            WTPrincipal wtp = (WTPrincipal) obj;
            TextDisplayComponent gui = new TextDisplayComponent("");
            if (s.equals("setPrincipalFullName"))
            {
                String curverstr = "";
                if (wtp instanceof WTUser)
                {
                    curverstr = ((WTUser) wtp).getFullName();
                }
                else
                    curverstr = ((WTGroup) wtp).getName();
                gui.setValue(curverstr);
            }
            else if (s.equals("wtprincipal_role"))
            {
                WTContainer container = modelcontext.getNmCommandBean().getContainer();

                StringBuffer strb = WorkFlowStepUtil.getRolesOfUser(container, wtp);
                gui.setValue(strb.toString());
            }
            guiComponentArray.addGUIComponent(gui);
            if (guiComponentArray.size() > 0)
                return guiComponentArray;
        }
        return DataUtilityHelper.getDefaultDataValue(s, obj, modelcontext);

    }
}
